POV-Ray : Newsgroups : povray.general : Making faster #switch statements : Re: Making faster #switch statements Server Time
12 Aug 2024 17:07:17 EDT (-0400)
  Re: Making faster #switch statements  
From: Thorsten Froehlich
Date: 5 Mar 1999 10:17:19
Message: <36dff57f.0@news.povray.org>
In article <MPG.1149eb79f78933399896a1@news.povray.org> , eag### [at] telekabelnl
(Phoenix) wrote:

> In general, the time it takes to read in a jump table is far greater than
> just using the jump system that gets generated by an if-clause.

That depends a lot on the density of the case conditions you have. Assume
you write a switch statement for the tokenizer in POV-Ray: You have most of
the ASCII characters and a high density of the numbers you compare. So the
compiler generates a jump table. It will most likely be somewhere around 128
entries. You need two comparisons plus branches (range checking) and one
jump. However, using a "if-clause jump system" you will in the worst case
have 128 comparsions and 128 conditional branches. Even if the processor
pipeline never gets interrupted you will still have 256 instructions
compared to only about 8 instructions. Compared to the "if-clause jump
system" average which would (assuming equal distribution, also for ASCII
characters (I used as example) it might be even worse) be 128 instructions -
not to mention the memory overhead...


     Thorsten


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.